<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加角色</title>
</head>
<body>

<form class="layui-form" lay-filter="layui-form"></form>
<div style="display: none" class="test1111"></div>
<script type="text/html" id="form">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <blockquote class="layui-elem-quote">副词条</blockquote>
                    <table class="layui-table" style="margin: 0;" lay-skin="line">
                        <colgroup>
                            <col width="30%">
                            <col width="30%">
                            <col width="30%">
                            <col width="10%">
                        </colgroup>
                        <thead>
                        <tr>
                            <th>副词条</th>
                            <th>角色</th>
                            <th>图片</th>
                        </tr>
                        </thead>
                        <tbody class="tableDnd">
                        <tr class="domainContent">
                            <td style="padding: 4px 15px;">
                                <input class="layui-input" type="text" name="sub_entry[]" value=""/>
                            </td>
                            <td style="padding: 4px 15px;">
                                <div class="layui-input-block">
                                    <div class="xmSelect"
                                         data-name="team_role5[]"
                                         data-sourceType="route"
                                         data-source="/admin.genshinteam.role/role"
                                         data-radio="false"
                                         data-textField="name"
                                         data-valueField="name"
                                         data-max="3"
                                    ></div>
                                </div>
                            </td>
                            <td style="padding: 4px 15px;">
                                <div class="layui-input-block">
                                    <div class="laytpUpload"
                                         data-name="icon-1"
                                         data-accept="image"
                                         data-type="ali-oss"
                                         data-showChoiceBtn="false"
                                         data-layVerify="required"
                                    ></div>
                                </div>
                            </td>
                            <td style="padding: 4px 15px;">
                                <a href="javascript:void(0);"
                                   class="layui-btn layui-btn-primary layui-btn-sm layui-icon layui-icon-delete delArrayItem"
                                   layer-tips="删除" title="删除"></a>
                            </td>
                        </tr>
                        <tr class='nodrop nodrag'>
                            <td colspan="4" style="padding: 4px 15px;">
                                <a href="javascript:void(0);" onclick="test()"
                                   class="layui-btn layui-btn-primary layui-btn-sm layui-icon layui-icon-add-1"
                                   title="追加">追加</a>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="laytp-btn laytp-btn-primary laytp-btn-sm" lay-submit="" lay-filter="add">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="laytp-btn laytp-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</script>
<script type="text/html" id="test">
    let i= 0;
    <tr>
        <td style="padding: 4px 15px;">
            <input class="layui-input" type="text" name="sub_entry[]" value=""/>
        </td>
        <td style="padding: 4px 15px;">
            <div class="layui-input-block">
                <div class="xmSelect"
                     data-name="team_role5[]"
                     data-sourceType="route"
                     data-source="/admin.genshinteam.role/role"
                     data-radio="false"
                     data-textField="name"
                     data-valueField="name"
                     data-max="3"
                ></div>
            </div>
        </td>
        <td style="padding: 4px 15px;">
            <div class="layui-input-block">
                <div class="laytpUpload"
                     data-name="icon[0]"
                     data-accept="image"
                     data-type="ali-oss"
                     data-showChoiceBtn="false"
                     data-layVerify="required"
                ></div>
            </div>
        </td>
        <td style="padding: 4px 15px;">
            <a href="javascript:void(0);"
               class="layui-btn layui-btn-primary layui-btn-sm layui-icon layui-icon-delete delArrayItem"
               layer-tips="删除" title="删除"></a>
        </td>
    </tr>
</script>
<script>
    if (localStorage.getItem("staticDomain")) {
        document.write("<link rel='stylesheet' href='" + localStorage.getItem("staticDomain") + "/component/layui/css/layui.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/layui/layui.js?v=" + localStorage.getItem("version") + "'><\/script>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/laytp/layuiConfig.js?v=" + localStorage.getItem("version") + "'><\/script>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/jquery_3.3.1.js?v=" + localStorage.getItem("version") + "'><\/script>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/jquery.tablednd.js?v=" + localStorage.getItem("version") + "'><\/script>");
    } else {
        document.write("<link rel='stylesheet' href='/static/component/layui/css/layui.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='/static/component/layui/layui.js?v=" + localStorage.getItem("version") + "'><\/script>");
        document.write("<script src='/static/component/laytp/layuiConfig.js?v=" + localStorage.getItem("version") + "'><\/script>");
        document.write("<script src='/static/component/jquery_3.3.1.js?v=" + localStorage.getItem("version") + "'><\/script>");
        document.write("<script src='/static/component/jquery.tablednd.js?v=" + localStorage.getItem("version") + "'><\/script>");
    }
</script>
<script>
    let layuiObject;
    layui.use(['laytp'], function () {
        let $ = layui.$;
        let form = layui.form;
        let attr = {}
        let formHtml;
        layuiObject = layui;
        renderHtml();
        window.test=function (){
            layui.laytpl($("#test").html()).render(attr,function(string){
                let testDom = $(".test1111");
                testDom.html(formHtml);
                testDom.find(".tableDnd").find(".nodrop").before(string);
                renderForm( testDom.html());
            });
        }
        function renderHtml(){
            layui.laytpl($("#form").html()).render(attr,function(string){
                renderForm(string)
            });
        }
        function renderForm(string){
            formHtml = string;
            $("form").html(string);
            layui.laytpForm.render();
            form.render();
        }

        layui.form.on('submit(add)', function (data) {
            var btnAnim = layui.button.load({elem: $(this)});
            facade.ajax({
                route: '/admin.genshinteam.role/add',
                data: data.field
            }).done(function (res) {
                if (res.code === 0) {
                    parent.layui.layer.close(parent.layui.layer.getFrameIndex(window.name));//关闭当前页
                    parent.layui.table.reload("laytp-table");
                }
                btnAnim.stop();
            }).fail(function () {
                btnAnim.stop();
            });
            return false;
        });
    })
</script>
</body>
</html>